from flask import Flask,request,flash
from flask import render_template

# 调用自定义模块中的函数

from research import researchletters
from timetable import table

# 调用自定义模块中的函数



# Flask:中央登记中心
app = Flask(__name__)
account_list=["haha","baobao","xiaot","qtao"]
password_list=["1002","2311","0401","0601"]

# 【Flask】(https://dormousehole.readthedocs.io/en/latest/quickstart.html#id10)
# 【HTMl】(https://www.w3school.com.cn/html/index.asp)
# 【jinja2】(https://palletsprojects.com/p/jinja/)

# 1. 路由：相对路径，决定了 页面资源 的路径，如果没有登记，将返回404 not found
# 1.1 url: 相对于：http://127.0.0.1：5000的相对路径
# 1.2 methods:【GET】【POST】
# 2. 视图函数：
# 2.1 函数过程决定了你操作的方法（实现的功能），例如 if elif else for while ...
# 2.2 return：返回数据内容，text文本，HTML文件（模板渲染），JSON文件等

# 【GET】
@app.route('/',methods=['GET'])
def hello_world():
    return render_template('hello.html')

@app.route('/hello',methods=['GET'])
def hello():
    return render_template('hello.html')

@app.route('/navbar',methods=['GET','POST'])
def navbar():
    return render_template('navbar.html')
# learn more 插入链接navbar导航链接

@app.route('/namecheck',methods=['GET','POST'])
def namecheck():
    return render_template('namecheck.html')
# nav第一个跳转链接

@app.route('/vowels',methods=['GET','POST'])
def vowels():
    return render_template('vowels.html')
# nav第二个跳转链接

@app.route('/shop',methods=['GET','POST'])
def shop():
    return render_template('shop.html')
# nav第三个链接跳转

@app.route('/nameresult',methods=['POST'])
def result_name():
    firstname = request.form.get("firstname")
    lastname = request.form.get("lastname")
    full_name = firstname.title() + ' ' + lastname.title()
    return render_template("checkout.html", name=full_name)
# checkout结果

@app.route('/words', methods=['POST', 'GET'])
def result_word():
    word = request.form.get("word")
    vowels = request.form.get("vowels")
    found = {}
    for i in word:
        if i in vowels:
            found.setdefault(i, 0)
            found[i] += 1
    for j in found:
        k = j
        v = found[j]

    return render_template("runvowels.html",
                           key=k,
                           value=v
                           )
# 输出词频结果

@app.route('/consume', methods=['GET','POST'])
def consume():
    return render_template('shopmarket.html')

@app.route('/xq',methods=['GET','POST'])
def xq():
    return render_template('xiangqing.html')


@app.route('/study', methods=['GET', 'POST'])
def study():
    return render_template('study.html')

@app.route('/inquiretime', methods=['GET'])
def input_time():
    return render_template('inquiretime.html')

@app.route('/courseover', methods=['POST'])
def courseover():
    py_week = request.form['week']
    py_hour = request.form['hour']
    py_minute = request.form['minute']
    py_time = int(py_hour + py_minute)
    py_class = table(py_week, py_time)
    return render_template('courseover.html',
                           timetables=py_class,
                           hourtime=py_hour,
                           minutetime=py_minute)

@app.route('/goumai',methods=['GET','POST'])
def goumai():
    return render_template('goumai.html')

